package com.qf.advice;

import org.aspectj.lang.ProceedingJoinPoint;

public class MyAdvice {

    public void writeLog(){
        System.out.println("记录日志");
    }

    public void afterReturning(Object result){//后置增强
        //后置增强在核心业务功能之后执行，可以拿到核心功能执行后的结果
        System.out.println("后置增强，执行完后拿到核心执行后的结果："+result);
    }

    public void around(ProceedingJoinPoint proceedingJoinPoint)throws Throwable{
        try {
            System.out.println("开启事务");
            //书写核心业务的执行
            Object proceed = proceedingJoinPoint.proceed();
            System.out.println("提交事务，结果是："+proceed);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void afterThrowing(Exception e){
        System.out.println("异常增强，核心业务出现了异常："+e.getMessage());
    }

    public void after(){
        System.out.println("最终增强，无论是否有异常都会执行");
    }
}
